<script setup lang="ts">
import { ref, reactive, onMounted, watch } from "vue";
import { useRoute } from "vue-router";
import { router } from "@/router";
import { tabsList, beianTabsList, subdomainTabsList } from "./helps";

import Config from "./components/Config.vue";
import BeianSearch from "./components/BeianSearch.vue";
import BeianList from "./components/BeianList.vue";
import SubdomainScan from "./components/SubdomainScan.vue";
import SubdomainList from "./components/SubdomainList.vue";

const route = useRoute();
const activeTab = ref("0");
const activeBeianTab = ref("search");
const activeSubdomainTab = ref("scan");

// 获取URL参数中的task
const taskParam = ref((route.query.task as string) || "");
</script>

<template>
  <div>
    <el-tabs v-model="activeTab" type="border-card">
      <el-tab-pane
        v-for="item in tabsList"
        :key="item.value"
        :label="item.label"
        :name="item.value"
      >
        <div
          v-if="taskParam"
          style="display: flex; justify-content: space-between"
        >
          <div class="task-name">任务名称：{{ taskParam }}</div>
        </div>

        <!-- 配置管理 -->
        <Config :task="taskParam" v-if="item.key === 'config'" />

        <!-- 备案域名管理 - 包含子tabs -->
        <div v-if="item.key === 'beian'">
          <el-tabs v-model="activeBeianTab" type="border-card">
            <el-tab-pane
              v-for="beianItem in beianTabsList"
              :key="beianItem.value"
              :label="beianItem.label"
              :name="beianItem.value"
            >
              <!-- 备案查询 -->
              <BeianSearch
                :task="taskParam"
                v-if="beianItem.key === 'beian_search'"
              />
              <!-- 列表查询 -->
              <BeianList
                :task="taskParam"
                v-if="beianItem.key === 'beian_list'"
              />
            </el-tab-pane>
          </el-tabs>
        </div>

        <!-- 子域名管理 - 包含子tabs -->
        <div v-if="item.key === 'subdomain'">
          <el-tabs v-model="activeSubdomainTab" type="border-card">
            <el-tab-pane
              v-for="subdomainItem in subdomainTabsList"
              :key="subdomainItem.value"
              :label="subdomainItem.label"
              :name="subdomainItem.value"
            >
              <!-- 扫描子域名 -->
              <SubdomainScan
                :task="taskParam"
                v-if="subdomainItem.key === 'subdomain_scan'"
              />
              <!-- 子域名列表 -->
              <SubdomainList
                :task="taskParam"
                v-if="subdomainItem.key === 'subdomain_list'"
              />
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style lang="scss" scoped>
:deep(.el-card__header) {
}

.search-form-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.el-btn-zese {
  background: #722ed1;
  color: white;
  border-color: #722ed1;
}

.el-btn-zese.is-disabled,
.el-btn-zese.is-disabled:focus,
.el-btn-zese.is-disabled:hover {
  background: #722ed1;
  color: white;
  border-color: #722ed1;
}
.task-name {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
  border: 1px solid #e0e0e0;
  padding: 10px;
  border-radius: 5px;
}
</style>
